package com.dajie.pt.util;


import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

/**
 * Created by zhihaosong on 23/07/15.
 */
public class DBUtil {
    private static Logger logger = LoggerFactory.getLogger(DBUtil.class);
    private static String driver = "com.mysql.jdbc.Driver";
    private static String url = "jdbc:mysql://cobarvip:12001/DB_BSS?autoCommit=true&autoReconnect=true&useUnicode=true&tinyInt1isBit=false&zeroDateTimeBehavior=round&characterEncoding=UTF-8&yearIsDateType=false&zeroDateTimeBehavior=convertToNull&socketTimeout=0";
    private static String user = "platformol";
    private static String password = "platformol-3";
    //    private static String url = "jdbc:mysql://localhost:3306/my?autoCommit=true&autoReconnect=true&useUnicode=true&tinyInt1isBit=false&zeroDateTimeBehavior=round&characterEncoding=UTF-8&yearIsDateType=false&zeroDateTimeBehavior=convertToNull";
//    private static String user = "root";
//    private static String password = "";
    private static Connection bssConnection = null;

    public static Connection getConnInstance() {
        createConnection();
        return bssConnection;
    }

    public static void createConnection() {

        try {
            Class.forName(driver);
            bssConnection = DriverManager.getConnection(url, user, password);
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }

    public static void close() {
        if (bssConnection != null)
            try {
                bssConnection.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
    }
}
